package com.msxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.msxt.dto.NewsEntity;
import com.msxt.mapper.NewsDao;
import com.msxt.result.Query;
import com.msxt.service.NewsService;
import com.msxt.utils.PageUtils;
import com.msxt.view.NewsView;
import com.msxt.vo.NewsVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 公告信息服务实现类
 */
@Service("newsService")
public class NewsServiceImpl extends ServiceImpl<NewsDao, NewsEntity> implements NewsService {


	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		QueryWrapper<NewsEntity> wrapper = new QueryWrapper<>();
		wrapper.eq("1", "1"); // 确保有基础条件

		Page<NewsEntity> page = this.page(
				new Query<NewsEntity>(params).getPage(),
				wrapper
		);
		return new PageUtils(page);
	}

	@Override
	public PageUtils queryPage(Map<String, Object> params, QueryWrapper<NewsEntity> wrapper) {
		// 确保wrapper包含正确的AND连接
		if (wrapper.isEmptyOfWhere()) {
			wrapper.eq("1", "1"); // 防止空WHERE子句
		}

		Page<NewsView> page = new Query<NewsView>(params).getPage();
		page.setRecords(baseMapper.listView(page, wrapper));
		return new PageUtils(page);
	}

	@Override
	public List<NewsVO> listVO(QueryWrapper<NewsEntity> wrapper) {
		return baseMapper.listVO(wrapper);
	}

	@Override
	public NewsVO selectVO(QueryWrapper<NewsEntity> wrapper) {
		return baseMapper.selectVO(wrapper);
	}

	@Override
	public List<NewsView> listView(QueryWrapper<NewsEntity> wrapper) {
		return baseMapper.listView(wrapper);
	}

	@Override
	public NewsView selectView(QueryWrapper<NewsEntity> wrapper) {
		return baseMapper.selectView(wrapper);
	}
}